package cn.iocoder.yudao.module.eval.service.filingmanagement;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.eval.controller.admin.filingmanagement.vo.*;
import cn.iocoder.yudao.module.eval.dal.dataobject.filingmanagement.FilingManagementDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.eval.dal.mysql.filingmanagement.FilingManagementMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.eval.enums.ErrorCodeConstants.*;

/**
 * 备案管理 Service 实现类
 *
 * @author 龙头企业
 */
@Service
@Validated
public class FilingManagementServiceImpl implements FilingManagementService {

    @Resource
    private FilingManagementMapper filingManagementMapper;

    @Override
    public Long createFilingManagement(FilingManagementSaveReqVO createReqVO) {
        // 插入
        FilingManagementDO filingManagement = BeanUtils.toBean(createReqVO, FilingManagementDO.class);
        // 显式设置deleted字段默认值
        filingManagement.setDeleted(false);
        filingManagementMapper.insert(filingManagement);

        // 返回
        return filingManagement.getId();
    }

    @Override
    public void updateFilingManagement(FilingManagementSaveReqVO updateReqVO) {
        // 校验存在
        validateFilingManagementExists(updateReqVO.getId());
        // 更新
        FilingManagementDO updateObj = BeanUtils.toBean(updateReqVO, FilingManagementDO.class);
        filingManagementMapper.updateById(updateObj);
    }

    @Override
    public void deleteFilingManagement(Long id) {
        // 校验存在
        validateFilingManagementExists(id);
        // 删除
        filingManagementMapper.deleteById(id);
    }

    @Override
        public void deleteFilingManagementListByIds(List<Long> ids) {
        // 删除
        filingManagementMapper.deleteByIds(ids);
        }


    private void validateFilingManagementExists(Long id) {
        if (filingManagementMapper.selectById(id) == null) {
            throw exception(FILING_MANAGEMENT_NOT_EXISTS);
        }
    }

    @Override
    public FilingManagementDO getFilingManagement(Long id) {
        return filingManagementMapper.selectById(id);
    }

    @Override
    public PageResult<FilingManagementDO> getFilingManagementPage(FilingManagementPageReqVO pageReqVO) {
        return filingManagementMapper.selectPage(pageReqVO);
    }

}